<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">
        #form2{
            text-align: center;
        }
        #img1{
            width: 400px;
            height: 400px;
        }
    </style>
</head>
<body>
<form action="userAction.php" method="post" id="form2" enctype="multipart/form-data">
    <h2>更换头像</h2>
    <input type="file" name="file" id="file" value="" multiple="multiple" onchange="showimg();"/>
    <div id="img2"><img src="" id="img1"><br/><br/></div>
    <input type="submit" name="" id="" value="更换" />
</form>
</body>
<script type="text/javascript">
    function showimg(){
        var fileObj = document.getElementById('file');
        var files = fileObj['files'];
        var URL = window.URL || window.webkitURL;
        var imgURL = URL.createObjectURL(files[0]);
        document.getElementById('img1').src = imgURL;
    }
</script>
</html>
